package binaryTree;

/**
 * 二叉树最大深度
 */
public class maxDepth {
    public int findMaxDepth(TreeNode root){
        if (root==null){
            return 0;
        }
        return maxNum(findMaxDepth(root.left),findMaxDepth(root.right))+1;
    }
    public static int maxNum(int a,int b){
        if (a<b){
            return b;
        }else{
            return a;
        }
    }

    public static void main(String[] args) {
        TreeNode root=new TreeNode(3);
        TreeNode node1=new TreeNode(9);
        TreeNode node2=new TreeNode(20);
        TreeNode node3=new TreeNode(15);
        TreeNode node4=new TreeNode(7);
        root.left=node1;
        root.right=node2;
        node2.left=node3;
        node2.right=node4;

        maxDepth maxDepth=new maxDepth();
        System.out.println(maxDepth.findMaxDepth(root));
    }

}
